import os
from fastapi import Cookie, HTTPException
from typing import Optional
from .config import Settings

settings = Settings()

def verify_password(password: str) -> bool:
    """验证密码是否正确"""
    print(f"Verifying password: {password}")
    print(f"Expected password: {settings.password}")
    return password == settings.password

def get_auth(auth: Optional[str] = Cookie(None)) -> bool:
    """验证用户是否已登录"""
    if not auth:
        raise HTTPException(status_code=401, detail="未登录")
    if not verify_password(auth):
        raise HTTPException(status_code=401, detail="登录已过期")
    return True 